<template>
  <div class="app-container">
    <div v-if="showCard">
      <el-card class="box-card">
        <div slot="header" class="clearfix">
          <span>指导教师意见</span>
        </div>
        <div v-if="form.status != '3'" >{{form.commentsOne}}</div>
        <el-input v-if="form.status == '3'" v-model="form.commentsOne" placeholder="请输入意见" style="width: 80%" />
        <!-- <ckeditor v-model="form.commentsOne" :config="editorConfig0"></ckeditor> -->
      </el-card>
      <el-card class="box-card" style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>指导单位意见</span>
        </div>
         <div v-if="form.status != '4'" >{{form.commentsTwo}}</div>
        <el-input v-if="form.status == '4'" v-model="form.commentsTwo" placeholder="请输入意见" style="width: 80%" />
        <!-- <ckeditor v-model="form.commentsTwo" :config="editorConfig1"></ckeditor> -->
      </el-card>
      <el-card class="box-card" style="margin-top: 20px;">
        <div slot="header" class="clearfix">
          <span>学校团委意见</span>
        </div>
        <div v-if="form.status != '5'" >{{form.commentsThree}}</div>
        <el-input v-if="form.status == '5'" v-model="form.commentsThree" placeholder="请输入意见" style="width: 80%" />
        <!-- <ckeditor v-model="form.commentsThree" :config="editorConfig2"></ckeditor> -->
      </el-card>
    </div>

    <div slot="footer" class="dialog-footer"  style="margin-top: 20px;">
      <el-button
        style="float: right"
        v-if="form.status == '3'"
        type="primary"
        @click="ispass('0')"
        v-hasPermi="['eqxm:team:check1']"
        >审核通过</el-button
      >
      <el-button
        style="float: right; margin-right: 20px"
        v-if="form.status == '3'"
        type="primary"
        @click="ispass('1')"
        v-hasPermi="['eqxm:team:check1']"
        >审核不通过</el-button
      >
      <el-button
        style="float: right"
        v-if="form.status == '4'"
        type="primary"
        @click="ispass('0')"
        v-hasPermi="['eqxm:team:check2']"
        >审核通过</el-button
      >
      <el-button
        style="float: right; margin-right: 20px"
        v-if="form.status == '4'"
        type="primary"
        @click="ispass('1')"
        v-hasPermi="['eqxm:team:check2']"
        >审核不通过</el-button
      >
      <el-button
        style="float: right"
        v-if="form.status == '5'"
        type="primary"
        @click="ispass('0')"
        v-hasPermi="['eqxm:team:check3']"
        >审核通过</el-button
      >
      <el-button
        style="float: right; margin-right: 20px"
        v-if="form.status == '5'"
        type="primary"
        @click="ispass('1')"
        v-hasPermi="['eqxm:team:check3']"
        >审核不通过</el-button
      >

      <el-button style="float: right; margin-right: 20px" type="primary" @click="back"
        >上一步</el-button
      >
      <!-- <el-button    v-hasPermi="['eqxm:team:edit']" style="float: right;" type="primary" @click="submitForm">提交</el-button> -->
    </div>
  </div>
</template>

<script>
import {
  listTeam,
  getTeam,
  delTeam,
  addTeam,
  updateTeam,
  exportTeam,
  ispass,
} from '@/api/eqxm/team';
import CommonUtils from '@/utils/CommonUtils';
import CKEditor from 'ckeditor4-vue';
import { mapGetters } from 'vuex';
export default {
  name: 'TeamExamine',
  components: {
    ckeditor: CKEditor.component,
  },
  computed: {
    ...mapGetters(['name', 'userName']),
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 团队表格数据
      teamList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        college: null,
        researchtopic: null,
        isimportant: null,
        presentation: null,
        presentationdetail: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      },
      isTeamTeacher: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      isimportantOptions: [],
      presentationOptions: [],
      researchtopicOptions: [],
      teamId: '',
      allMoney: 0,
      editorConfig0: {
        readOnly: true,
      },
      editorConfig1: {
        readOnly: true,
      },
      editorConfig2: {
        readOnly: true,
      },
      showCard: false,
    };
  },
  created() {
    this.init();
    this.getDicts('researchtopic').then(response => {
      this.researchtopicOptions = response.data;
    });
  },
  methods: {
    /** 查询团队列表 */
    init() {
      const id = CommonUtils.getCurTeamInfo().id;
      this.teamId = id;
      getTeam(id).then(response => {
        this.form = response.data;
        if(this.form){
            this.form.commentsOne = this.form.commentsOne?this.form.commentsOne.replace("<p>",""):""
            this.form.commentsOne = this.form.commentsOne?this.form.commentsOne.replace("</p>",""):""
            this.form.commentsTwo = this.form.commentsTwo?this.form.commentsTwo.replace("<p>",""):""
            this.form.commentsTwo = this.form.commentsTwo?this.form.commentsTwo.replace("</p>",""):""
            this.form.commentsThree = this.form.commentsThree?this.form.commentsThree.replace("<p>",""):""
            this.form.commentsThree = this.form.commentsThree?this.form.commentsThree.replace("</p>",""):""
          }
        if (this.form.eqxmTeamTeacherList) {
          for (var i = 0; i < this.form.eqxmTeamTeacherList.length; i++) {
            if (this.form.eqxmTeamTeacherList[i].username == this.name) {
              this.isTeamTeacher = true;
            }
          }
        }
        console.log(888, this.form);
        if (this.form.status == '3') {
          this.editorConfig0.readOnly = false;
          this.editorConfig1.readOnly = true;
          this.editorConfig2.readOnly = true;
        } else if (this.form.status == '4') {
          this.editorConfig0.readOnly = true;
          this.editorConfig1.readOnly = false;
          this.editorConfig2.readOnly = true;
        } else if (this.form.status == '5') {
          this.editorConfig0.readOnly = true;
          this.editorConfig1.readOnly = true;
          this.editorConfig2.readOnly = false;
        }
        this.showCard = true;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        name: null,
        delFlag: null,
        college: null,
        createBy: null,
        researchtopic: null,
        isimportant: null,
        createTime: null,
        presentation: null,
        updateBy: null,
        presentationdetail: null,
        updateTime: null,
        transportation: null,
        accommodation: null,
        publicity: null,
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      //清空store的项目信息
      let teamInfo = {};
      CommonUtils.setCurTeamInfo(teamInfo);
      const vm = this;
      vm.$router.push({
        //核心语句
        path: '/team/teamManage', //跳转的路径
        query: { type: 0 },
      });
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;
      getTeam(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = '修改团队';
      });
    },
    /** 提交按钮 */
    submitForm() {
      const vm = this;
      this.$refs['form'].validate(valid => {
        if (valid) {
          let that = this;
          if (this.form.id != null) {
            updateTeam(this.form).then(response => {
              this.$parent.jump(1);
              // this.open = false;
              //this.getList();
            });
          } else {
            addTeam(this.form).then(response => {
              this.$modal.msgSuccess('新增成功');
              let teamInfo = {
                id: response,
              };
              CommonUtils.setCurTeamInfo(teamInfo);
              const id = CommonUtils.getCurTeamInfo();
              this.$parent.isCreate = false;
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$confirm('是否确认删除团队编号为"' + ids + '"的数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return delTeam(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess('删除成功');
        });
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有团队数据项?', '警告', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      })
        .then(function () {
          return exportTeam(queryParams);
        })
        .then(response => {
          this.download(response.msg);
        });
    },
    moneyChange() {
      this.allMoney = this.form.transportation + this.form.accommodation + this.form.publicity;
    },
    ispass(no) {
      var ispassVal = false
      switch (this.form.status) {
        case "3":
          ispassVal = !!this.form.commentsOne
          break;
        case "4":
          ispassVal = !!this.form.commentsTwo
          break;
        case "5":
          ispassVal = !!this.form.commentsThree
          break;
      }
      console.log(ispassVal,"ispassVal")
      if(no=='0' || ispassVal){
        this.form.ispass = no;
        this.$confirm('确认提交审核？', '提示', { type: 'warning' }).then(() => {
          ispass(this.form).then(response => {
            if (response.code === 200) {
              this.$modal.msgSuccess('审核成功');
              this.open = false;
              this.init();
              this.$router.push({
                //核心语句
                path: '/eqxm/team', //跳转的路径
              });
            }
          });
        });
      }else{
        this.$modal.msgError('请先填写意见');
      }
    },
    back() {
      this.$parent.jump(4);
    },
  },
};
</script>
